﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 理财
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            if (double.TryParse(txtPrincipal.Text, out double principal) &&
                double.TryParse(txtRate.Text, out double rate) &&
                int.TryParse(txtYears.Text, out int years))
            {
                txtResult.Clear(); 
                double amount = principal; 
                rate = rate / 100; 

                for (int i = 1; i <= years; i++)
                {
                    amount = amount * (1 + rate); 
                    txtResult.AppendText($"存{i}年：{amount:F2}\n"); 
                }
            }
            else
            {
                MessageBox.Show("输入内容不符合要求，请输入有效的数值！", "提示");
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtPrincipal.Clear();
            txtRate.Clear();
            txtYears.Clear();
            txtResult.Clear();
        }
    }
}
